package com.travelsky.airchina.boarding.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;
import org.springframework.stereotype.Service;

import com.travelsky.airchina.boarding.common.ConstType;
import com.travelsky.airchina.boarding.dao.MemberDAO;
import com.travelsky.airchina.boarding.domain.Member;
import com.travelsky.airchina.boarding.service.MemberService;

@Service("memberService")
public class MemberServiceImpl implements MemberService {
	@Autowired
	private MemberDAO memberDAO;
	private PasswordEncoder encoder = new ShaPasswordEncoder();
	public void saveOrUpdateMember(Member member) {
		String encodePassword = encoder.encodePassword(member.getLoginPassword(),ConstType.SALT_PRI+member.getLoginName());
		member.setLoginPassword(encodePassword);
		memberDAO.makePersistent(member);
	}
	public boolean isExistLoginName(String loginName) {
		return memberDAO.isExistLoginName(loginName);
	}
	public boolean isExistEmail(String email) {
		return memberDAO.isExistEmail(email);
	}
	public Member getMember(String loginName) {
		return memberDAO.getMember(loginName);
	}
	public Member getMember(Long id) {
		return memberDAO.findById(id);
	}

}
